package com.jsmile.cloud.msgcenter.pay.repo;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jsmile.cloud.msgcenter.pay.dao.PayOrderDao;
import com.jsmile.cloud.msgcenter.pay.model.PayOrderInfo;
import com.jsmile.mall.api.exception.ExceptionKit;

import lombok.extern.slf4j.Slf4j;

/**
 * @author 龚亮
 * @version 1.0
 * @desc 为了薪资破万，还是睡一会儿吧...!
 * @date 2020年06月07日 11:19:01
 */
@Service
@Slf4j
@Transactional(readOnly = true, rollbackFor = Exception.class)
public class PayOrderSearchRepository extends ServiceImpl<PayOrderDao, PayOrderInfo> {

    public List<PayOrderInfo> findByOutTradeNo(String outTradeNo) {
        List<PayOrderInfo> payOrderInfos = this.baseMapper.selectList(new QueryWrapper<PayOrderInfo>().lambda().eq(PayOrderInfo::getOutTradeNo, outTradeNo));
        ExceptionKit.checkNotNull(payOrderInfos, "支付信息不存在!");
        return payOrderInfos;
    }

    public List<PayOrderInfo> findByOrderNos(List<Long> orderNos) {
        List<PayOrderInfo> payOrderInfos = this.baseMapper.selectList(new QueryWrapper<PayOrderInfo>().lambda().in(PayOrderInfo::getOrderNo, orderNos));
        ExceptionKit.checkNotNull(payOrderInfos, "支付信息不存在!");
        return payOrderInfos;
    }

    public PayOrderInfo findByOrderNo(Long orderNo) {
        PayOrderInfo payOrderInfos = this.baseMapper.selectOne(new QueryWrapper<PayOrderInfo>().lambda().eq(PayOrderInfo::getOrderNo, orderNo));
        ExceptionKit.checkNotNull(payOrderInfos, "支付信息不存在!");
        return payOrderInfos;
    }
}
